import time

from django.utils import timezone
from django.contrib.auth.models import User

from django.db import models


# Create your models here.
class DailyNews(models.Model):
    created_time = models.DateTimeField("创建时间", default=timezone.now)
    # time_describe = models.CharField("描述时间", max_length=70)
    body = models.TextField("正文")
    title = models.CharField("标题", max_length=50, default="unknown")
    status = models.CharField("状态", max_length=20)
    like_cnt = models.PositiveIntegerField(default=0, editable=True)
    pic_own = models.CharField("图片所属", blank=True, max_length=50, default=time.strftime("%d-%m-%Y %H"))

    class Meta:
        verbose_name = "日常消息"
        verbose_name_plural = verbose_name

    def increase_like(self):
        self.like_cnt += 1
        self.save(update_fields=["like_cnt"])

    def __str__(self):
        return "{}: {}".format(self.status, self.body[:20])
